#include <stdio.h>
#include <string.h>

#include "Pipe.h"

#define LINE_MAXLEN 128

const char *func_names[] = {
	"clear",
	"push",
	"pop",
	"head",
	"tail",
	"isempty"
};

const char *quit_cmd = "quit";


int
main(void)
{
	struct Pipe p;
	char line[LINE_MAXLEN];
	int key = 0;

	p.head = 0;
	p.size = 0;

	while (scanf("%s", line) == 1) {
		if (!strcmp(line, func_names[0])) {
			Clear(&p);
		} else if (!strcmp(line, func_names[1])) {
			if (scanf("%d", &key) != 1)
				printf("\tExpected int, aborting\n");
			else
				if (Push(&p, key) == -1)
					printf("\tFailed to push - queue overflow\n");
		} else if (!strcmp(line, func_names[2]))
			printf(" %d\n", Pop(&p));
		else if (!strcmp(line, func_names[3]))
			printf(" %d\n", Head(&p));
		else if (!strcmp(line, func_names[4]))
			printf(" %d\n", Tail(&p));
		else if (!strcmp(line, func_names[5]))
			printf(" %s\n", IsEmpty(&p) ? "Yes, pipe is empty" : "No, pipe aint empty");
		else if (!strcmp(line, quit_cmd))
			return 0;
		else
			printf("\tWrong function name\n");
	}
	fprintf(stderr, "  Leaving so soon?\n");
	return 0;
}
